package com.sczmgk.track.db.impl;

import android.content.Context;

import com.sczmgk.track.db.UserDao;
import com.sczmgk.track.db.base.DAOSupport;
import com.sczmgk.track.entity.User;
import com.sczmgk.track.utils.CacheUtils;

/**
 * Created by chenb on 2016/12/6.
 */

public class UserDaoImpl extends DAOSupport<User> implements UserDao {

    private UserDaoImpl(Context context) {
        super(context);
    }

    private static UserDaoImpl intance;

    public static UserDaoImpl getIntance(Context context) {
        if (intance == null) {
            intance = new UserDaoImpl(context);
        }
        return intance;
    }

    public static boolean isExists(Context context, int uid) {
        return UserDaoImpl.getIntance(context).isExists(uid);
    }

    public static User findByUid(Context context, int uid) {
        return UserDaoImpl.getIntance(context).findByQuery(uid);
    }

    public static void updateUser(Context context, User userNews, User user) {
        userNews.setId(user.getId());
        userNews.imageLocalPath = user.imageLocalPath;
        //存入数据库
        UserDaoImpl.getIntance(context).updata(userNews);
    }

    public static User getLoginUser(Context context) {
        return UserDaoImpl.getIntance(context).findByQuery(CacheUtils.getLoginUserid(context));
    }


//    public static String getLoginPhone(Context context) {
//        User user = UserDaoImpl.getIntance(context).findByQuery(CacheUtils.getLoginUserid(context));
//        if ( user != null) {
//            return user.phone;
//        }else{
//            return "" ;
//        }
//    }

//    public static String getLoginAddress(Context context) {
//        User user = UserDaoImpl.getIntance(context).findByQuery(CacheUtils.getLoginUserid(context));
//        if ( user != null) {
//            return user.address;
//        }else{
//            return "" ;
//        }
//    }
}
